<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	EntityCreate
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

	<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>

	<script type="text/javascript">
		function AddRow() {
			var newNum = $('tr.PropertyRow').length;

			var newElenent = $(
				'<tr class = "PropertyRow" id = "PropertyRowId' + newNum + '">' +
				'<td><input name = "tableGenericEntity.Properties[' + newNum + '].key"/></td>' +
				'<td><input name = "tableGenericEntity.Properties[' + newNum + '].value"/></td>' +
				'<td><input type="button" value="Delete" onclick="DeleteRow(' + newNum + ')"/></td>' +
				'</tr>');

			newElenent.appendTo('#tProperties');
		}

		function DeleteRow(rowId) {
			var deletedItem = $('#PropertyRowId' + rowId);
			deletedItem.remove();
		}
	</script>

	<h2>
		EntityCreate</h2>
	<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
	<% using (Html.BeginForm())
		{%>
	<%=Html.Hidden("storageId", ViewData["storageId"])%>
	<%=Html.Hidden("storageBoxId", ViewData["storageBoxId"])%>
	<fieldset>
		<legend>Fields</legend>
		<p>
			<label for="PartitionKey">
				PartitionKey:</label>
			<%= Html.TextBox("tableGenericEntity.PartitionKey", String.Empty)%>
			<%= Html.ValidationMessage("PartitionKey", "*") %>
		</p>
		<p>
			<label for="RowKey">
				RowKey:</label>
			<%= Html.TextBox("tableGenericEntity.RowKey", String.Empty)%>
			<%= Html.ValidationMessage("RowKey", "*") %>
		</p>
		<div>
			Properties
			<table id="tProperties">
				<tr>
					<th>
						Name
					</th>
					<th>
						Values
					</th>
					<th>
					</th>
				</tr>
			</table>
			<input type="button" value="Add" onclick="AddRow()" />
		</div>
		<p>
			<input type="submit" value="Create" />
		</p>
	</fieldset>
	<% } %>
	<div>
		<%=Html.ActionLink("Back to Rows", "Rows", new { storageId = ViewData["storageId"], storageBoxId = ViewData["storageBoxId"] })%>
	</div>
</asp:Content>
